

class AbstractView{
    static LEVEL_1 = 1
    static LEVEL_2 = 2
    static LEVEL_3 = 3
    constructor(level){
        this.level = level
    }
    rander(){
        throw new Error("rander")
    }
    setNextView(nextView){
        this.nextView = nextView
    }
    execuse(level){//级别低的让儿子处理。再高级别给父亲，父亲处理不了给爷爷
        if(this.level>=level){
            this.rander()
            return
        }
        if(this.nextView){
            this.nextView.rander()
        }
    }
}

class SonView extends AbstractView{
    constructor(level){
        super(level)
    }
    rander(){
        console.log("儿子页面渲染")
    }
}

class ParentView extends AbstractView{
    constructor(level){
        super(level)
    }
    rander(){
        console.log("父类页面渲染")
    }
}

class GrandPaView extends AbstractView{
    constructor(level){
        super(level)
    }
    rander(){
        console.log("爷爷页面渲染")
    }
}

const sonView = new SonView(AbstractView.LEVEL_1)
const pView = new ParentView(AbstractView.LEVEL_2)
const gView = new GrandPaView(AbstractView.LEVEL_3)
sonView.setNextView(pView)
pView.setNextView(gView)

// sonView.execuse(AbstractView.LEVEL_3)



//=========================用例2====================

class AbstractAna{
    nextAna =null
    setNextAna(nextAna){
        this.nextAna = nextAna
    }
    setObj(obj){
        this.obj = obj
    }
    filter(obj){
        if(typeof obj == "object"){
            this.setObj(obj)
        }else if(typeof obj == "string"){
            try {
                this.setObj(JSON.parse(obj))
            } catch (error) {
                console.log("解析完成")
                // throw new Error("解析完成")
                return true
            }
        } else if(typeof obj =="number"){
            console.log("解析完成")
            return true
        }else{
            throw new Error("传递的数据异常")
        }
    }
    execuse(obj){
        if(obj){
            if(this.filter(obj)){
                return
            }
            this.ana(this.obj)
        }
        if(this.nextAna){
            this.nextAna.execuse(this.obj)
        }
        
    }
    ana(obj){
        throw new Error("ana error")
    }
}
class Enter extends AbstractAna{
    constructor(){
        super()
    }
    ana(obj){
        super.setObj(obj)
    }
}
class AnaHead extends AbstractAna{
    constructor(){
        super()
    }
    ana(obj){
        super.setObj(obj&&obj.head?obj.head:obj)
        if(obj.head){
            console.log("头部信息：",obj.head)
        }
    }
}
class AnaBody extends AbstractAna{
    constructor(){
        super()
    }
    ana(obj){
        super.setObj(obj&&obj.body?obj.body:obj)
        if(obj&&obj.body){
            console.log("body内容：",obj.body)
        }
    }
}

class AnaMsg extends AbstractAna{
    constructor(){
        super()
    }
    ana(obj){
        if(obj&&obj.msg){
            super.setObj(obj.msg)
            console.log("解析头部内部内容：",obj.msg)
        }else{
            super.setObj(obj)
        }
    }
}

class AnaContent extends AbstractAna{
    constructor(){
        super()
    }
    ana(obj){
        if(obj.msg_content){
            super.setObj(obj.msg_content)
            console.log("body内部内容：",obj.msg_content)
        }else{
            super.setObj(obj)
        }
    }
}

const obj = {head:{msg:"123"},body:{msg_content:"msgcontent",head:{msg:"sdsfg"}}}
const obj2 = {msg:"3455"}

// const enter = new Enter()
const anaBody  = new AnaBody()
const anaHead = new AnaHead()
const anaMsg = new AnaMsg()
const anaContent = new AnaContent()
// enter.setNextAna(anaBody)
anaBody.setNextAna(anaHead)
anaHead.setNextAna(anaMsg)
anaMsg.setNextAna(anaContent)
anaContent.setNextAna(anaBody)
anaBody.execuse(obj)



